<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>类的基本知识</title>
</head>
<body>
    <script type="text/javascript">
        let arr1 = [1,2,3];
        let arr2 = [4,5,6];
        //展开一个数组
        console.log(...arr1);
        //拼接数组
        console.log([...arr1,...arr2]);
        //在函数中使用
        function sum(...numbers){
            return numbers.reduce((pre,cur)=>pre+cur);
        }
        console.log(sum(1,2,3,4,5));

        //构造字面量对象时使用展开语法
        let person = {name:'tom',age:18}
        //下面用{}包裹的展开运算符是克隆对象的语法
        let person2 = {...person}
        //下面语句报错，在js的原生运算符中展开运算符是不能展开对象的，只能展开数组
        //consile.log(...person);
        person.name = 'jerry';
        console.log(person2);
        console.log(person);

        //复制对象的同时修改对象的名字
        let person3 = {...person,name:'jack',address:"地球"}
        console.log(person3);


    </script>
</body>
</html>